package com.yupi.springbootinit.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class MyMain {

    private static final String EXCHANGE_NAME = "code-exchange";
    public static void main(String[] args) {

        try{
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            channel.exchangeDeclare(EXCHANGE_NAME, "direct");

            // 创建队列，随机分配一个队列名称，并绑定到 "xiaoyu" 路由键
            String queueName = "code_queue";
            // 声明队列，设置队列为持久化的，非独占的，非自动删除的
            channel.queueDeclare(queueName, true, false, false, null);
            // 将队列绑定到指定的交换机上，并指定绑定的路由键为 "xiaoyu"
            channel.queueBind(queueName, EXCHANGE_NAME, "my_routingkey");
        } catch (Exception e) {

        }

    }
}
